package com.zhijian.warehouse.manage.controller;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.vo.request.*;
import com.zhijian.warehouse.manage.entity.vo.response.AccessFacilityRecordVo;
import com.zhijian.warehouse.manage.entity.vo.response.AccessProductRecordVo;
import com.zhijian.warehouse.manage.service.AccessFacilityRecordService;
import com.zhijian.warehouse.manage.service.AccessProductRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仪器领用归记录 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-10-28 17:42:45
 */
@Slf4j
@Controller
@Api(tags = "仪器领用归记录")
public class AccessProductRecordController {

    @Autowired
    private AccessProductRecordService service;

    @Autowired
    private AccessFacilityRecordService accessFacilityRecordService;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record")
    @ApiOperation("新增")
    public boolean insert(@RequestBody AccessProductRecordSaveOrUpdateVo param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/access/product/record/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/access/product/record/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody AccessProductRecordSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.modify(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/access/product/record/{id}")
    @ApiOperation("根据id查询")
    public AccessProductRecordVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record/page")
    @ApiOperation("仪器领用归还记录")
    public Page<AccessProductRecordVo> selectByCondition(@RequestBody(required = false) AccessProductRecordSearchVo param) {
        if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 违规领用记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/facility/record/illegal/page")
    @ApiOperation("违规领用记录")
    public Page<AccessFacilityRecordVo> selectIllegalByCondition(@RequestBody(required = false) AccessFacilityRecordSearchVo param) {
        if (param == null)
            param = AccessFacilityRecordSearchVo.builder().build();
        log.info("{} - {}| selectIllegalByCondition info", this.getClass().getSimpleName(), param);
        param.setIsViolator(1);
        return accessFacilityRecordService.selectPage(param);
    }

    /**
     * 超期未归还记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record/overdue/page")
    @ApiOperation("超期未归还记录")
    public Page<AccessProductRecordVo> selectOverdueByCondition(@RequestBody(required = false) AccessProductRecordSearchVo param) {
        if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
        log.info("{} - {}| selectOverdueByCondition info", this.getClass().getSimpleName(), param);
        return service.selectOverdueByCondition(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/record/list")
    @ApiOperation("列表查询")
    public List<AccessProductRecordVo> selectList(@RequestBody(required = false) AccessProductRecordSearchVo param) {
        if (param == null)
            param = AccessProductRecordSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    @Response
    @DeleteMapping("/access/product/record/list")
    @ApiOperation("批量删除")
    public boolean delete(@RequestBody(required = false) List<Long> idList) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), idList);
        service.deleteByIdList(idList);
        return true;
    }
    
    /**
     * 归还
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/back")
    @ApiOperation("归还")
    public boolean back(@RequestBody AccessProductBackVo param) {
        log.info("{} - {}| back info", this.getClass().getSimpleName(), param);
        return service.back(param);
    }
    
    /**
     * 延长领用时间
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/access/product/extend")
    @ApiOperation("延长领用天数")
    public boolean extend(@RequestBody AccessProductExtendVo param) {
        log.info("{} - {}| extend info", this.getClass().getSimpleName(), param);
        return service.extend(param);
    }

}
